import cv2
import os

import time
import multiprocessing as mp
from  predict import predict_class

inter_time = 5
elapsed_time = 0
channel =1
user_name, user_pwd = "admin", "@qwertyuiop159"
camera_ip_l = ["192.168.137.2"] 
camera_ip = "192.168.137.2"
cap = cv2.VideoCapture(
    "rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (user_name, user_pwd, camera_ip, channel))
while True:
    frame = cap.read()[1]
    frame = cv2.resize(frame, (640, 480))
    cv2.imshow("camera", frame)
    elapsed_time = elapsed_time + 1
    if(elapsed_time > 30 * inter_time):
        elapsed_time = 0
        filename = f'frames/frame_{str(time.strftime("%S"))}.jpg'
        cv2.imwrite(filename, frame)
        predict_class(filename)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()